package com.tuo51.evaluate.repositories.tags;

import com.tuo51.evaluate.domain.tags.Tag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TagRepository extends JpaRepository<Tag, String> , JpaSpecificationExecutor<Tag> {

    Tag findByTitleAndMonth(String tagName, Integer month);

    Tag findByTitleAndHidden(String title, Boolean hidden);

    @Query(value = "SELECT * FROM `m_tag` t where t.`id` in " +
            "(SELECT r.`tagId` FROM  `mrel_object_tag` r where r.`objId` = ?1 and `objType` = ?2)", nativeQuery = true)
    List<Tag> findAllByRelationObjId(String relationObjId, Integer type);

}
